var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mainColor: app.globalData.mainColor,
    baseImgUrl: app.globalData.baseImgUrl,
    dataList: [],
    current: 1,
    size: 10,
    stop: false,
  },

  //数据列表
  getDataList() {
    const that = this;
    if (that.data.stop) {
      return;
    }
    let params = {
      "current": this.data.current,
      "size": this.data.size
    };
    // app.http.post('/gd-fishing/user/concern/list', params).then((res) => {
    //   // console.log('http-res:', JSON.stringify(res));
    //   if (app.errorAlert(res)) {
    //     return;
    //   }
    //   let records = res.data.records;
    //   if (records.length == 0) {
    //     that.setData({
    //       stop: true
    //     });
    //     return;
    //   }
    //   records.forEach(item => {
    //     item.concern = true;
    //   });
    //   that.setData({
    //     dataList: records
    //   });
    // })
    let res = {
      "code": 1,
      "msg": "成功",
      "data": {
        "records": [{
          "userId": 8,
          "userPhone": null,
          "nickName": "月下蓑衣客",
          "headImg": "/20241115/1731634694721.jpeg",
          "signDesc": "路虽远，行则将至！",
          "userSex": null
        }],
        "total": 1,
        "size": 10,
        "current": 1,
        "pages": 1
      },
      "remarks": null
    };
    let records = res.data.records;
    if (records.length == 0) {
      that.setData({
        stop: true
      });
      return;
    }
    records.forEach(item => {
      item.concern = true;
    });
    that.setData({
      dataList: records
    });
  },

  //关注
  concern(e) {
    let that = this;
    let index = e.currentTarget.dataset.val;
    let tempList = that.data.dataList;
    app.http.get('/gd-fishing/user/concern/' + tempList[index].userId).then((res) => {
      // console.log('http-res:', JSON.stringify(res));
      if (app.errorAlert(res)) {
        return;
      }
      let val = tempList[index].concern;
      that.setData({
        ['dataList[' + index + '].concern']: !val
      })
      // console.log("dataList:", that.data.dataList);
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getDataList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.setData({
      current: this.data.current + 1
    });
    this.getDataList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})